﻿@{
    Layout = "/Views/Shared/_Layout.cshtml";
}


@*中间主页面*@
<div class="content-wrap">
    <div class="content">
        @*Banner*@
        <div id="focusslide" class="carousel slide" data-ride="carousel">
            @*小圆点*@
            <ol class="carousel-indicators">
            </ol>

            @*banner图片*@
            <div class="carousel-inner" role="listbox">
            </div>
            <a class="left carousel-control" href="#focusslide" role="button" data-slide="prev" rel="nofollow"> <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> <span class="sr-only">上一个</span> </a> <a class="right carousel-control" href="#focusslide" role="button" data-slide="next" rel="nofollow"> <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> <span class="sr-only">下一个</span> </a>
        </div>

        <div class="title">
            <h3>最新发布</h3>
        </div>

        @*文章列表*@
        <div id="home_news">
        </div>
    </div>
</div>

@*右侧侧边栏信息*@
<aside class="sidebar">
    <div class="fixed">
        <div class="widget widget-tabs">
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="active"><a href="#notice" aria-controls="notice" role="tab" data-toggle="tab">统计信息</a></li>
                <li role="presentation"><a href="#contact" aria-controls="contact" role="tab" data-toggle="tab">联系站长</a></li>
            </ul>
            <div class="tab-content">
                <div role="tabpanel" class="tab-pane contact active" id="notice">
                    <h2>
                        新闻总数:
                        <text id="newsCount"></text>篇
                    </h2>
                    <h2>
                        网站运行:
                        <span id="sitetime">5年以上 </span>
                    </h2>
                </div>
                <div role="tabpanel" class="tab-pane contact" id="contact">
                    <h2>
                        QQ:2835806641
                        <a href="" target="_blank" rel="nofollow" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="QQ:"></a>
                    </h2>
                    <h2>
                        Email:2835806641@qq.com
                        <a href="#" target="_blank" data-toggle="tooltip" rel="nofollow" data-placement="bottom" title="" data-original-title="#"></a>
                    </h2>
                </div>
            </div>
        </div>
        <div class="widget widget_search">
            <form class="navbar-form" action="/Search" method="post">
                <div class="input-group">
                    <input type="text" name="keyword" id="keyword" class="form-control" size="35" placeholder="请输入关键字" maxlength="15" autocomplete="off">
                    <span class="input-group-btn">
                        <button class="btn btn-default btn-search" name="search" onclick="searchOneNews()" type="button">搜索</button>
                    </span>
                </div>
            </form>
        </div>
    </div>
    <div class="widget widget_hot">
        <h3>最新评论文章</h3>

        @*最新评论新闻列表*@
        <ul id="new_comment">
        </ul>
    </div>
    <div class="widget widget_sentence">
        <a href="http://study.163.com/instructor/1025318795.htm" target="_blank" rel="nofollow">
            <img style="width: 100%" src="/images//201610241224221511.jpg" alt="专业网站建设">
        </a>
    </div>
    <div class="widget widget_sentence">
        <a href="http://study.163.com/instructor/1025318795.htm" target="_blank" rel="nofollow">
            <img style="width: 100%" src="/images/ad.jpg">
        </a>
    </div>
    <div class="widget widget_sentence">
        <h3>友情链接</h3>
        <div class="widget-sentence-link">
            <a href="http://study.163.com/instructor/1025318795.htm" title=".net core视频教程中心" target="_blank">.net core视频教程中心</a>&nbsp;&nbsp;&nbsp;
        </div>
    </div>
</aside>


<script type="text/javascript">
    $(function () {
        getBanner();
        getNewsCount();
        getHomeNews();
        getNewsCommentsList();
    });

    //获取banner集合并渲染
    function getBanner() {
        $.ajax({
            type: "get",
            url: "/Home/GetBanner",
            success: function (result) {
                if (result.code == 200) {
                    $(".carousel-inner").empty();
                    $(".carousel-indicators").empty();

                    var bannerHtml = "";
                    var pointHtml = "";//banner图上的小圆点

                    for (var i = 0; i < result.data.length; i++) {
                        var item = result.data[i];
                        if (i == 0) {
                            bannerHtml += "<div class=\'item active\'>";
                            bannerHtml += "<a href=\'#\' target=\'_blank\'>";
                            bannerHtml += "<img src=\'" + item.image + "\' class=\'img-responsive\'>";
                            bannerHtml += "</a>";
                            bannerHtml += "</div>";

                            pointHtml += " <li data-target=\'#focusslide\' data-slide-to=\'0\' class=\'active\'></li>";
                        } else {
                            bannerHtml += "<div class=\'item\'>";
                            bannerHtml += "<a href=\'#\' target=\'_blank\'>";
                            bannerHtml += "<img src=\'" + item.image + "\' class=\'img-responsive\'>";
                            bannerHtml += "</a>";
                            bannerHtml += "</div>";

                            pointHtml += "<li data-target=\'#focusslide\' data-slide-to=\'" + i + "\'></li>";
                        }
                    }
                    $(".carousel-inner").append(bannerHtml);
                    $(".carousel-indicators").append(pointHtml);
                }
            }
        });
    }

    //获取新闻总数
    function getNewsCount() {
        $.ajax({
            type: "get",
            url: "/Home/GetNewsCount",
            success: function (result) {
                if (result.code == 200) {
                    $("#newsCount").text(result.data);
                }
            }
        });
    }

    //获取新闻列表的前几条数据
    function getHomeNews() {
        $.ajax({
            type: "get",
            url: "/Home/GetHomeNewsList",
            success: function (result) {
                if (result.code == 200) {
                    $("#home_news").empty();
                    var newsHtml = "";

                    for (var i = 0; i < result.data.length; i++) {
                        var item = result.data[i];
                        newsHtml += "<article class=\'excerpt excerpt-1\'>";
                        newsHtml += "<a class=\'focus\' href=\'/News/Detail?newsid=" + item.id + "\' title=\'" + item.title + "\' target=\'_blank\'><img class=\'thumb\' data-original=\'" + item.image + "\' src=\'" + item.image + "\' alt=\'" + item.title + "\' style=\'display: inline;\'></a>";
                        newsHtml += "<header>";
                        newsHtml += "<h2>";
                        newsHtml += "<a href=\'/News/Detail?newsid=" + item.id + "\' title=\'" + item.title + "\' target=\'_blank\'>" + item.title + "</a>";
                        newsHtml += "</h2>";
                        newsHtml += "</header>";
                        newsHtml += "<p class=\'meta\'>";
                        newsHtml += "<time class=\'time\'><i class=\'glyphicon glyphicon-time\'></i>" + item.publishDate + "</time>";
                        newsHtml += "<a class=\'comment\' title=\'评论\' target=\'_blank\'><i class=\'glyphicon glyphicon-comment\'></i> " + item.conmmentCount + "</a>";
                        newsHtml += "</p>";
                        newsHtml += "<p class=\'note\'>" + item.contents + "</p>";
                        newsHtml += "</article>";
                    }
                    $("#home_news").append(newsHtml);
                }
            }
        });
    }

    //获取最新被评论的新闻前N条记录
    function getNewsCommentsList() {
        $.ajax({
            type: "get",
            url: "/Home/GetNewsCommentsList",
            success: function (result) {
                if (result.code == 200) {
                    $("#new_comment").empty();
                    var newsCommentHtml = "";

                    for (var i = 0; i < result.data.length; i++) {
                        var item = result.data[i];
                        newsCommentHtml += "<li>";
                        newsCommentHtml += "<a title=\'" + item.title + "\' href=\'/News/Detail?newsid=" + item.id + "\'>";
                        newsCommentHtml += "<span class=\'thumbnail\'>";
                        newsCommentHtml += "<img class=\'thumb\' data-original=\'" + item.image + "\' src=\'" + item.image + "\' alt=\'" + item.title + "\' style=\'display: block;\'>";
                        newsCommentHtml += "</span><span class=\'text\'>" + item.title + "</span><span class=\'muted\'>";
                        newsCommentHtml += "<i class=\'glyphicon glyphicon-time\'></i>";
                        newsCommentHtml += item.publishDate;
                        newsCommentHtml += "</a>";
                        newsCommentHtml += "</li>";
                    }
                    $("#new_comment").append(newsCommentHtml);
                }
            }
        });
    }

    //搜索新闻
    function searchOneNews() {
        var keyword = $.trim($("#keyword").val());
        if (keyword != "" && keyword != null) {
            $.ajax({
                type: "get",
                url: "/Home/SearchOneNews",
                data: { keyword: keyword },
                success: function (result) {
                    if (result.code == 200) {
                        window.open("/News/Detail?newsid=" + result.data);
                    } else {
                        window.open("/Home/Wrong");
                    }
                }
            });
        }
    }

</script>